﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using System.ComponentModel;
using DTC.Popups;
using DTC.Database;

namespace DTC.Pages
{
    /// <summary>
    /// Interaction logic for DrugPrescriptionPage.xaml
    /// </summary>
    public partial class DrugManagementPage : Page
    {
        public DrugManagementPage()
        {
            InitializeComponent();
            SetOrders();
            OrdersListBox.ItemsSource = orders;

        }        

        private ObservableCollection<DTCOrder> orders;

        private void SetOrders()
        {
            orders = new ObservableCollection<DTCOrder>(App.DBI.GetAllOrders());
        }

        private void DrugDictionaryButton_Click(object sender, RoutedEventArgs e)
        {
            DrugsDictionaryPopup ddp = new DrugsDictionaryPopup();
            ddp.Owner = App.Current.MainWindow;
            ddp.ShowDialog();
        }

        private void OrderingOptionsButton_Click(object sender, RoutedEventArgs e)
        {            
        }

        private void AddDrugToStoreButton_Click(object sender, RoutedEventArgs e)
        {
            OrderPopup op = new OrderPopup();
            op.Owner = App.Current.MainWindow;
            if (op.ShowDialog() == true)
            {
                orders.Add(op.Order);
            }
        }

        private void ViewOrder_Click(object sender, RoutedEventArgs e)
        {
            Button cmd = (Button)sender;
            DTCOrder selectedOrder = (DTCOrder)cmd.Tag;
            OrderPopup op = new OrderPopup();
            op.Owner = App.Current.MainWindow;
            op.Order = selectedOrder;
            op.ShowDialog();
            OrdersListBox.Items.Refresh();
        }

        private void DeleteOrder_Click(object sender, RoutedEventArgs e)
        {

        }
    }
}
